
    /**  
    * @Title: MacroDefineController.java
    * @Package com.efast.cafe.portal.controller.common
    * @Description: TODO(用一句话描述该文件做什么)
    * @author Administrator
    * @date 2019年1月15日
    * @version V1.0  
    */
    
package com.efast.cafe.portal.controller.common;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.constant.CommonConstant;
import com.efast.cafe.framework.enums.ResultStatus;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.cafe.portal.bean.company.PortalCompanyUserOrgBean;
import com.efast.cafe.portal.entity.base.PortalBaseParameter;
import com.efast.cafe.portal.service.base.IBaseCompanyInfoService;
import com.efast.cafe.portal.service.common.IParameterService;
import com.efast.cafe.portal.service.company.IPortalCompanyUserService;
import com.efast.cafe.util.UUIDUtils;
import com.efast.cafe.util.date.DateUtils;

/**
    * @ClassName: MacroDefineController
    * @Description: TODO(这里用一句话描述这个类的作用)
    * @author Administrator
    * @date 2019年1月15日
    *
    */
@Controller
public class MacroDefineController {
	
	final String ALL="all";

	final String MACRO_USERNAME="userName";
	final String MACRO_COMPANYCODE="companyCode";
	final String MACRO_REALNAME="realName";
	final String MACRO_COMPANYNAME="companyName";
	final String MACRO_EMAIL="email";
	final String MACRO_SYSTEMNAME="systemName";
	final String MACRO_USERIMG="userImg";
	final String MACRO_TIME="currentTime";
	final String MACRO_ORG="org";
	@Autowired
	private IBaseCompanyInfoService baseCompanyInfoService;
	@Autowired
	private IParameterService parameterService;
	@Autowired
	private IPortalCompanyUserService portalCompanyUserService;
	
	@RequestMapping("/frame_center/common/macro/{code}")
	public @ResponseBody ResultBean macro(@PathVariable("code") String code){
		ResultBean res = new ResultBean(true);
		switch(code){
			case MACRO_USERNAME:
				res.setObject(SpringWebUtils.getRequestUser());break;
			case MACRO_COMPANYCODE:
				res.setObject(SpringWebUtils.getRequestCompany());break;
			case MACRO_REALNAME:
				res.setObject(SpringWebUtils.getRequestUserObj().getReal_name());break;
			case MACRO_COMPANYNAME:
				res.setObject(baseCompanyInfoService.queryByCode().getCompany_name());break;
			case MACRO_EMAIL:
				res.setObject(SpringWebUtils.getRequestUserObj().getEmail());break;
			case MACRO_SYSTEMNAME:
				PortalBaseParameter parameter = parameterService.getParameter(CommonConstant.ParameterKeys.WEB_INDEX_SYSTEM_NAME,
						CommonConstant.ModuleName.GLOBAL, SpringWebUtils.getRequestCompany(), null);
				res.setObject(parameter!=null ? parameter.getParam_value() : null);break;
			case MACRO_TIME:
				res.setObject(DateUtils.format(new Date(), DateUtils.FORMAT_DATE_YYYY_MM_DD_HH_MM_SS));break;
			case MACRO_ORG:
				PortalCompanyUserOrgBean uo = portalCompanyUserService.queryUserAndOrgInfo();
				res.setObject(uo!=null ? uo.getOrgs() : null);break;
			case ALL:
				JSONObject jo = new JSONObject();
				jo.put(MACRO_USERNAME, SpringWebUtils.getRequestUser());
				jo.put(MACRO_COMPANYCODE, SpringWebUtils.getRequestCompany());
				jo.put(MACRO_REALNAME, SpringWebUtils.getRequestUserObj().getReal_name());
				jo.put(MACRO_COMPANYNAME, baseCompanyInfoService.queryByCode().getCompany_name());
				jo.put(MACRO_EMAIL, SpringWebUtils.getRequestUserObj().getEmail());
				
				PortalBaseParameter parameter1 = parameterService.getParameter(CommonConstant.ParameterKeys.WEB_INDEX_SYSTEM_NAME,
						CommonConstant.ModuleName.GLOBAL, SpringWebUtils.getRequestCompany(), null);
				jo.put(MACRO_SYSTEMNAME, parameter1!=null ? parameter1.getParam_value() : null);
				jo.put(MACRO_TIME, DateUtils.format(new Date(), DateUtils.FORMAT_DATE_YYYY_MM_DD_HH_MM_SS));
				PortalCompanyUserOrgBean uo1 = portalCompanyUserService.queryUserAndOrgInfo();
				jo.put(MACRO_ORG, uo1!=null ? uo1.getOrgs() : null);
				res.setObject(jo);break;
			default:
				res.setSuccess(false);
				res.setErrorCode(ResultStatus.PARAM_ERROR.getCode());
				break;
		}
		return res;
	}
}
